﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common"
    xmlns:Controls.Common.Interactivity="clr-namespace:Imagin.Controls.Common.Interactivity"
    xmlns:System="clr-namespace:System;assembly=mscorlib">
    <Common.Data.Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <Common.Data.Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
    <Common.Data.Converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
    <Common.Data.Converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
    
    <Style x:Key="{x:Type local:UpDown}" TargetType="{x:Type local:UpDown}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:UpDown}">
                    <Border 
                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <ScrollViewer 
                                x:Name="PART_ContentHost" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                Margin="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Grid 
                                Grid.Column="1"
                                Margin="0,0,5,0"
                                Visibility="{Binding CanUpDown, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <local:MaskedButton 
                                    x:Name="PART_Up"
                                    Focusable="False"
                                    ImageWidth="10" 
                                    ImageHeight="10" 
                                    Margin="5,0,0,0"
                                    Command="{Binding UpCommand, RelativeSource={RelativeSource TemplatedParent}}"
                                    CommandParameter="Up"
                                    Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowUp.png"/>
                                <local:MaskedButton 
                                    Grid.Row="1" 
                                    x:Name="PART_Down"
                                    Focusable="False"
                                    ImageWidth="10" 
                                    ImageHeight="10" 
                                    Margin="5,0,0,0"
                                    Command="{Binding DownCommand, RelativeSource={RelativeSource TemplatedParent}}"
                                    CommandParameter="Down"
                                    Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowDown.png"/>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type local:DateTimeUpDown}" TargetType="{x:Type local:DateTimeUpDown}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:DateTimeUpDown}">
                    <Border 
                        x:Name="PART_Border"
                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <ScrollViewer 
                                x:Name="PART_ContentHost" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                Margin="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Grid 
                                Grid.Column="1"
                                Visibility="{Binding CanUpDown, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <local:MaskedButton 
                                    x:Name="PART_Up"
                                    Focusable="False"
                                    ImageWidth="10" 
                                    ImageHeight="10" 
                                    Margin="5,0,0,0"
                                    Command="{Binding UpCommand, RelativeSource={RelativeSource TemplatedParent}}"
                                    CommandParameter="Up"
                                    Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowUp.png"/>
                                <local:MaskedButton 
                                    Grid.Row="1" 
                                    x:Name="PART_Down"
                                    Focusable="False"
                                    ImageWidth="10" 
                                    ImageHeight="10" 
                                    Margin="5,0,0,0"
                                    Command="{Binding DownCommand, RelativeSource={RelativeSource TemplatedParent}}"
                                    CommandParameter="Down"
                                    Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowDown.png"/>
                            </Grid>
                            <local:MaskedToggleButton
                                Grid.Column="2"
                                IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                Padding="5,0"
                                Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowDownSmall.png"
                                Visibility="{Binding IsReadOnly, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Inverted, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Popup
                                x:Name="PART_DropDown"
                                Placement="{TemplateBinding DropDownPlacement}"
                                PlacementTarget="{Binding ElementName=PART_Border}"
                                PopupAnimation="{TemplateBinding DropDownAnimation}"
                                StaysOpen="{TemplateBinding StaysOpen}"
                                Width="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}">
                                <i:Interaction.Behaviors>
                                    <Controls.Common.Interactivity:AutoPositionPopupBehavior />
                                </i:Interaction.Behaviors>
                                <Border Style="{TemplateBinding DropDownStyle}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Calendar 
                                            x:Name="PART_Calendar"
                                            SelectedDate="{Binding Value, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                                            DisplayDate="{Binding Value, Mode=OneTime, RelativeSource={RelativeSource TemplatedParent}}"
                                            DisplayMode="Month"/>
                                        <local:AdvancedComboBox
                                            Grid.Row="1"
                                            x:Name="PART_TimeBox"
                                            IsEditable="True"
                                            Margin="0,10,0,0"
                                            SelectedValue="{Binding Value, Mode=OneWay}">
                                            <local:AdvancedComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Mode=OneWay, StringFormat=t}"/>
                                                </DataTemplate>
                                            </local:AdvancedComboBox.ItemTemplate>
                                        </local:AdvancedComboBox>
                                    </Grid>
                                </Border>
                            </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="DropDownStretch" Value="None">
                            <Setter TargetName="PART_DropDown" Property="Width" Value="Auto"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>